package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "套餐管理")
@Slf4j
@RequestMapping("/admin/setmeal")
@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result<String> addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐：{}", setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 分页查询套餐列表
     * @param setmealPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询套餐列表")
    @GetMapping("/page")
    public Result<PageResult> querySetmealList(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("分页查询套餐列表：{}", setmealPageQueryDTO);
        return Result.success(setmealService.querySetmealList(setmealPageQueryDTO));
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result<String> deleteSetmealBench(@RequestParam List<Long> ids) {
        log.info("批量删除套餐：{}", ids);
        setmealService.deleteSetmealBench(ids);
        return Result.success();
    }

    /**
     * 根据id查询套餐详情
     * @param id
     * @return
     */
    @ApiOperation("根据id查询套餐详情")
    @GetMapping("/{id}")
    public Result<SetmealVO> querySetmealById(@PathVariable Long id) {
        log.info("根据id查询套餐详情：{}", id);
        return Result.success(setmealService.querySetmealById(id));
    }

    /**
     * 设置套餐状态
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("设置套餐状态")
    @PostMapping("/status/{status}")
    public Result<String> setSetmealStatus( Long id, @PathVariable Integer status) {
        log.info("设置套餐状态：id={}, status={}", id, status);
        setmealService.setSetmealStatus(id, status);
        return Result.success();
    }

    /**
     * 更新套餐
     * @param setmealDTO
     * @return
     */
    @ApiOperation("更新套餐")
    @PutMapping
    public Result<String> updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("更新套餐：{}", setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
}
